﻿Imports DataObject
Imports BusinessObject
Imports Microsoft.ApplicationBlocks.Data

Public Class frmHangHoaVatTuList

    Private oHangHoa As New BusHangHoa
    Private oPrHangHoa As New HangHoa
    Private oConn As New hDBase
    Private cboLoaiHangHoa As New Infragistics.Win.UltraWinGrid.UltraCombo

    Private Sub frmHangHoaVatTuList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitData()
        LoadGridView()
        RefreshToolbar()
        LoadAllCombo()
    End Sub

    Protected Overrides Sub LoadDataGrid()
        Try
            tableDictionary = oHangHoa.GetAllHangHoa(sConn)
            ListBindingSource.DataSource = tableDictionary
            grdList.DataSource = ListBindingSource
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LoadGridView()
        Try
            grdList.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
            With grdList.DisplayLayout.Bands(0)
                .Columns("SoHH").Hidden = True
                .Columns("DonVi").Hidden = True
                .Columns("DonViChuyenDoi").Hidden = True
                .Columns("TyLeChuyenDoi").Hidden = True
                .Columns("ThoiHanBaoHanh").Hidden = True
                .Columns("SoLuongToiThieu").Hidden = True
                .Columns("DonGiaMua").Hidden = True
                .Columns("DonGiaBan").Hidden = True
                .Columns("ThueSuat").Hidden = True
                .Columns("SoDoiTuong").Hidden = True
                .Columns("DienGiai").Hidden = True

                .Columns("MaHH").Header.Caption = "Mã hàng hóa, vật tư"
                .Columns("TenHH").Header.Caption = "Tên hàng hóa, vật tư"
                .Columns("SoLoaiHH").Header.Caption = "Loại hàng hóa, vật tư"
                .Columns("HoatDong").Header.Caption = "Được sử dụng"

            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Protected Overrides Sub InitAddNewRow(ByVal oRow As System.Data.DataRow)
        With oRow
            .Item("MaHH") = ""
            .Item("TenHH") = ""
            .Item("HoatDong") = True
        End With
    End Sub

    Protected Overrides Function DeleteDictionary() As Boolean
        oPrHangHoa.SoHH = iValue
        oHangHoa.DeleteHangHoa(sConn, oPrHangHoa)
    End Function

    Private Sub grdList_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdList.MouseClick
        Try
            iValue = grdList.ActiveRow.Cells(TablePrimaryKey).Value
        Catch ex As Exception
        End Try
    End Sub

    Private Sub LoadAllCombo()
        Dim ds As New DataSet
        ds.Clear()
        If (Not ds.Tables("LoaiHangHoa") Is Nothing) Then
            ds.Tables("LoaiHangHoa").Rows.Clear()
        End If
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Get_All_LoaiHangHoas", ds, New String() {"LoaiHangHoa"})
        With cboLoaiHangHoa
            .DataSource = ds.Tables("LoaiHangHoa")
            .DisplayMember = "TenLoaiHH"
            .ValueMember = "SoLoaiHH"
            .DisplayLayout.Load(PathLayout & "cboChucDanh.lyt")
        End With
        grdList.DisplayLayout.Bands(0).Columns("SoLoaiHH").EditorControl = cboLoaiHangHoa
        grdList.DisplayLayout.Bands(0).Columns("SoLoaiHH").CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit
    End Sub

End Class
